    /*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cuong.bean;

import client.entity.Category;
import client.entity.QuantityCategory;
import java.util.ArrayList;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import org.hibernate.Hibernate;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import util.HibernateUtil;

/**
 *
 * @author Admin Windows 8
 */
@ManagedBean
@SessionScoped
public class CategoryQuantityBean {

    /**
     * Creates a new instance of CategoryQuantityBean
     */
    public CategoryQuantityBean() {
    }
    private List<QuantityCategory> list;

    public List<QuantityCategory> getList() {
        list= new ArrayList<QuantityCategory>();        
        SessionFactory factory = HibernateUtil.getSessionFactory();
        Session ss = factory.openSession();
        ss.getTransaction().begin();
        List result = ss.createSQLQuery("SELECT Category.Category_Name, COUNT(Recruitment_Category.ID_Recruitment) AS 'QuantityReqm'" +
" FROM Category LEFT JOIN Recruitment_Category  ON Category.ID =  Recruitment_Category.ID_Category" +
" GROUP BY Category.Category_Name ORDER BY COUNT(Recruitment_Category.ID_Category)DESC").addScalar("Category_Name",Hibernate.STRING).addScalar("QuantityReqm",Hibernate.INTEGER).list();
         for (Object object : result) {
                Object[] lstO = (Object[]) object;               
                QuantityCategory qc = new QuantityCategory();               
                qc.setNamecate(lstO[0].toString());
                qc.setQuantity(Integer.parseInt(lstO[1].toString()));       
                list.add(qc);          
            }
        ss.getTransaction().commit();
        ss.close();
        return list;
    }

    public void setList(List<QuantityCategory> list) {
        this.list = list;
    }
    
}
